<script setup>
import {ref, onUnmounted, nextTick} from "vue";

import Telemetry from "@/views/Telemetry/Index.vue"
// 接收方：监听广播通道中的消息
const channel = new BroadcastChannel('telemetryChannel');
const localData = ref(null)
const lastTime = ref(null)
// 监听消息
// 确保在接收到消息时更新数据
channel.onmessage = (event) => {
	localData.value = event.data;
	lastTime.value = new Date().toLocaleString('zh-CN', {hour12: false}).replace(/\//g, '/')
};
// 发送方
onUnmounted(() => {
	channel.close();
	channel.onmessage = null
});
</script>
<template>
	<n-layout class="h-full">
		<Telemetry :is-new-windows="true" :data="localData" :last-time="lastTime"></Telemetry>
	</n-layout>
</template>